package PengendaliSuratDokumen;

import java.awt.HeadlessException;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JOptionPane;
import oracle.jdbc.pool.OracleDataSource;

public class PengendaliTabel {
// Membuat tabel ---------------------------------------------------------------

    public static void membuatTabelDokumen() {
        KoneksiOracle koneksiOracle = new KoneksiOracle();
        koneksiOracle.getDBConnection();
        Connection conn = koneksiOracle.conn;
        try {
            OracleDataSource ods = new OracleDataSource();
            Statement stat = conn.createStatement();
            String dokumen = "CREATE TABLE DOKUMEN(NO_DOKUMEN VARCHAR(20),"
                    + "PERIHAL VARCHAR2(20) NOT NULL,"
                    + "ASAL VARCHAR2(20) NOT NULL,"
                    + "PENERIMA VARCHAR2(20) NOT NULL,"
                    + "RUANG VARCHAR2(10),"
                    + "LEMARI VARCHAR2(10),"
                    + "LOKER VARCHAR2(10),"
                    + "NAMA_PETUGAS VARCHAR2(20),"
                    + "TANGGAL_TERIMA VARCHAR2(20),"
                    + "constraint NO_DOKUMEN primary key (NO_DOKUMEN) ENABLE)";

            stat.executeQuery(dokumen);

            JOptionPane.showMessageDialog(null, "Koneksi OK!" + "\nTabel DOKUMEN Berhasil Dibuat");
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Error 2:" + e.getMessage());
        }
    }

    public static void membuatTabelSurat() {
        KoneksiOracle koneksiOracle = new KoneksiOracle();
        koneksiOracle.getDBConnection();
        Connection conn = koneksiOracle.conn;
        try {
            OracleDataSource ods = new OracleDataSource();
            Statement stat = conn.createStatement();
            String surat = "CREATE TABLE SURAT(NO_SURAT VARCHAR2(40),"
                    + "PERIHAL VARCHAR2(20) NOT NULL,"
                    + "ASAL VARCHAR2(100),"
                    + "PENERIMA VARCHAR2(20) NOT NULL,"
                    + "RUANG VARCHAR2(100),"
                    + "LEMARI VARCHAR2(100),"
                    + "LOKER VARCHAR2(100),"
                    + "NAMA_PETUGAS VARCHAR2(100),"
                    + "TANGGAL_TERIMA VARCHAR2(10),"
                    + "constraint NO_SURAT primary key (NO_SURAT) ENABLE)";
            stat.executeQuery(surat);
            JOptionPane.showMessageDialog(null, "Koneksi OK!" + "\nTabel SURAT Berhasil Dibuat");
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Error :" + e.getMessage());
        }
    }
//    public static void membuatTabelPenerima() {
//        KoneksiOracle koneksiOracle = new KoneksiOracle();
//        koneksiOracle.getDBConnection();
//        Connection conn = koneksiOracle.conn;
//        try {
//            OracleDataSource ods = new OracleDataSource();
//            Statement stat = conn.createStatement();
//            String penerima = "CREATE table PENERIMA (ID_PENERIMA VARCHAR2(10) NOT NULL,"
//                    + "NAMA VARCHAR2(100) NOT NULL,"
//                    + "constraint PENERIMA_PK primary key (ID_PENERIMA) ENABLE)";
//            stat.executeQuery(penerima);
//            JOptionPane.showMessageDialog(null, "Koneksi OK!" + "\nTabel PENERIMA Berhasil Dibuat");
//        } catch (Exception e) {
//            JOptionPane.showMessageDialog(null, "Error :" + e.getMessage());
//        }
//
//    }
//
//    public static void membuatTabelSekretariat() {
//        KoneksiOracle koneksiOracle = new KoneksiOracle();
//        koneksiOracle.getDBConnection();
//        Connection conn = koneksiOracle.conn;
//        try {
//            OracleDataSource ods = new OracleDataSource();
//            Statement stat = conn.createStatement();
//            String sekretariat = "CREATE table SEKRETARIAT (ID_SEKRE VARCHAR2(10) NOT NULL,"
//                    + "NAMA VARCHAR2(100) NOT NULL,"
//                    + "constraint SEKRETARIAT primary key (ID_SEKRE) ENABLE)";
//            stat.executeQuery(sekretariat);
//            JOptionPane.showMessageDialog(null, "Koneksi OK!" + "\nTabel SEKRETARIAT Berhasil Dibuat");
//        } catch (Exception e) {
//            JOptionPane.showMessageDialog(null, "Error :" + e.getMessage());
//        }
//    }
// Menghapus tabel -------------------------------------------------------------
//    public static void menghapusTabelDokumen() {
//        KoneksiOracle koneksiOracle = new KoneksiOracle();
//        koneksiOracle.getDBConnection();
//        Connection conn = koneksiOracle.conn;
//        try {
//            Statement stat = conn.createStatement();
//            OracleDataSource ods = new OracleDataSource();
//            String dokumen = "drop table DOKUMEN";
//            stat.executeQuery(dokumen);
//            JOptionPane.showMessageDialog(null, "Tabel DOKUMEN dan Seluruh Data\nBerhasil Dihapus");
//        } catch (SQLException | HeadlessException e) {
//            JOptionPane.showMessageDialog(null, "Error :" + e.getMessage());
//        }
//    }
//
//    public static void menghapusTabelSurat() {
//        KoneksiOracle koneksiOracle = new KoneksiOracle();
//        koneksiOracle.getDBConnection();
//        Connection conn = koneksiOracle.conn;
//        try {
//            Statement stat = conn.createStatement();
//            OracleDataSource ods = new OracleDataSource();
//            String surat = "drop table SURAT";
//            stat.executeQuery(surat);
//
//            JOptionPane.showMessageDialog(null, "Tabel SURAT dan Seluruh Data\nBerhasil Dihapus");
//        } catch (SQLException | HeadlessException e) {
//            JOptionPane.showMessageDialog(null, "Error :" + e.getMessage());
//        }
//    }
//    public static void menghapusTabelPenerima() {
//        KoneksiOracle koneksiOracle = new KoneksiOracle();
//        koneksiOracle.getDBConnection();
//        Connection conn = koneksiOracle.conn;
//        try {
//            Statement stat = conn.createStatement();
//            OracleDataSource ods = new OracleDataSource();
//            String penerima = "drop table PENERIMA";
//            stat.executeQuery(penerima);
//            JOptionPane.showMessageDialog(null, "Tabel PENERIMA dan Seluruh Data\nBerhasil Dihapus");
//        } catch (SQLException | HeadlessException e) {
//            JOptionPane.showMessageDialog(null, "Error :" + e.getMessage());
//        }
//    }
//
//    public static void menghapusTabelSekretariat() {
//        KoneksiOracle koneksiOracle = new KoneksiOracle();
//        koneksiOracle.getDBConnection();
//        Connection conn = koneksiOracle.conn;
//        try {
//            Statement stat = conn.createStatement();
//            OracleDataSource ods = new OracleDataSource();
//            String sekretariat = "drop table SEKRETARIAT";
//            stat.executeQuery(sekretariat);
//            JOptionPane.showMessageDialog(null, "Tabel SEKRETARIAT dan Seluruh Data\nBerhasil Dihapus");
//        } catch (SQLException | HeadlessException e) {
//            JOptionPane.showMessageDialog(null, "Error :" + e.getMessage());
//        }
//    }
}